#ifndef SIGNALDATA_H
#define SIGNALDATA_H

#include <iostream>
#pragma once

#include <QObject>
#include <QVariant>
#include <QMap>
#include <QString>
#include <QMetaEnum>

#if defined(PLUGINCORE_LIBRARY)
#define PLUGINCORE_EXPORT Q_DECL_EXPORT
#else
#define PLUGINCORE_EXPORT Q_DECL_IMPORT
#endif

/**
 *SignalData封装体
 **/
class  PLUGINCORE_EXPORT SignalData : public QObject
{
    Q_OBJECT

public:

    enum Msg
    {
        Sys,
        KeyPress,
        Normal,
        Custom=0x1000,
        User=0x2000
    };

    Q_ENUM(Msg)

    int type=Normal;   //消息类型：Sys、Normal、...
    QString action;
    QString from;       //消息sender
    QString to;         //消息receiver

    QMap<QString,QVariant> map; //传递非指针参数
    void *dataPtr = nullptr;  //用于传递指针参数


    SignalData(){ }
    SignalData(int typeA){ type=typeA;}
    SignalData(int typeA,void *ptr){ type=typeA;dataPtr=ptr;}
    SignalData(QString fromA,QString toA){ from=fromA;to=toA;}

    friend  QDataStream &operator<<(QDataStream & ds, const SignalData &msg)
    {ds<<"action:" << msg.action <<" from:" << msg.from << "  to:" << msg.to<<"  type: " << QMetaEnum::fromType<SignalData::Msg>().key(msg.type) ;
        return ds;}

    friend inline QDebug operator<<(QDebug out, const SignalData &msg)
    {
        out <<"action:" << msg.action <<" from:" << msg.from << "  to:" << msg.to<<"  type: " << QMetaEnum::fromType<SignalData::Msg>().key(msg.type) ;
        return out;
    }

    QString toString(){return "action:" +action + " from:" +from + "  to:" +to+"  type: " +QMetaEnum::fromType<SignalData::Msg>().key(type) ;}


};


Q_DECLARE_METATYPE(SignalData);  //确保类型可以通过信号槽传递


#endif // SIGNALDATA_H
